package zm.irc.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import org.apache.log4j.Logger;
import zm.irc.connpool.DbConnectionPool;
import zm.irc.dto.InterestingTextInfo;
import zm.irc.ioc.annotation.AutoWired;
import zm.irc.ioc.annotation.Service;


@Service
public class InterestingTextDao {
    Logger log = Logger.getLogger(MessageDao.class);

    @AutoWired
    private DbConnectionPool dbConnectionPool;
    
    public void saveMessage(InterestingTextInfo msg){
        Connection conn = null;
        PreparedStatement ps = null;
        try {
                conn = dbConnectionPool.getConnection();
                if(conn == null){
                    return;
                }
               
                ps = conn.prepareCall("insert into IRC_INTERESTING_TEXT (type," +
                        "hash_value," +
                        "value," +
                        "source) values(?,?,?,?)");
                ps.setString(1,msg.getType());
                ps.setString(2,msg.getHashValue());
                ps.setString(3,msg.getValue());
                ps.setString(4,msg.getSource());
             ps.execute();

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            DbConnectionPool.close(ps);
            DbConnectionPool.close(conn);
        }
    }

}
